package com.example.robertluozizhao.baseframedemo.function.registerOrLogin.login.view;

import android.app.ProgressDialog;
import android.widget.EditText;
import android.widget.Toast;

import com.example.robertluozizhao.baseframedemo.R;
import com.example.robertluozizhao.baseframedemo.base.BaseActivity;
import com.example.robertluozizhao.baseframedemo.function.registerOrLogin.login.LoginConstract.LoginConstract;
import com.example.robertluozizhao.baseframedemo.function.registerOrLogin.login.bean.User;
import com.example.robertluozizhao.baseframedemo.function.registerOrLogin.login.presenter.UserLoginPresenter;


import butterknife.Bind;
import butterknife.OnClick;

/**
 * Created by robert.luozizhao on 2017/9/5 0005.
 *
 */

public class UserLoginActivity extends BaseActivity implements LoginConstract.LoginView<User>{


    @Bind(R.id.et_username)
    EditText etUsername;
    @Bind(R.id.et_password)
    EditText etPassword;

    private UserLoginPresenter mUserLoginPresenter;
    private ProgressDialog mProgressDialog;

    @Override
    public int getLayout() {
        return R.layout.activity_login;
    }

    @Override
    public void initView() {
        super.initView();
        mProgressDialog = new ProgressDialog(this);
    }

    @OnClick(R.id.btnLogin)
    public void onViewClicked() {
        mUserLoginPresenter = new UserLoginPresenter(this);
        mUserLoginPresenter.getListData();
        mProgressDialog.show();
    }

    @Override
    public void loginSuccess(User data) {
        //1 停止进度条  2 成功展示
        mProgressDialog.dismiss();
        Toast.makeText(this,"名字："+data.getUsername()+";密码："+data.getPassword(),Toast.LENGTH_SHORT).show();
    }

    @Override
    public void loginFailed(String error) {
        //1 停止进度条  2 失败展示
        mProgressDialog.dismiss();
        Toast.makeText(this,error,Toast.LENGTH_SHORT).show();
    }

    @Override
    public String getUsername() {
        return etUsername.getText().toString().trim();
    }

    @Override
    public String getPassword() {
        return etPassword.getText().toString().trim();
    }

    @Override
    public void refreshData(User data) {

    }

}
